/*
 * server_mgr.h
 *
 *  Created on: Dec 26, 2013
 *      Author: killerg
 */

#ifndef SERVER_MGR_H_
#define SERVER_MGR_H_

#include "share/patterns.h"
#include "share/http_s.h"
struct server_session_t;


struct player_info_t {
    string account;
    string playername;
    int32_t playerid;
};

struct order_t {
    string orderId;
    int32_t playerid;
    double payfee;
    bool dealt;
    string machinecode;
};

struct server_info_t {
    list<order_t*> orders;
    ptr_map<string, player_info_t*, unordered_map<string, player_info_t*> > players;    // key account
    server_session_t* sess;
};

struct server_mgr_t {
    ptr_map<int, server_info_t*> serverinfos;    // key serverid
    unordered_set<string> dealt_order;

    player_info_t* get_player_info(int serverid, const string &account);
    void refresh_player_info(int serverid, const string &account, const player_info_t &info);
    void post_order(int serverid, const string &orderId, int playerid, int money, const string &machinecode, function<void(bool)> cb);
    bool init();
    void destroy();
    void update();

    int32_t order_post_delta = 0;
    int32_t order_post = 0;
    int32_t order_post_prev = 0;
    int32_t db_set = 0;
};

#endif /* SERVER_MGR_H_ */
